package com.salon.client.beans;

import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;

public class WhereBean implements IsSerializable {
	public enum Type implements IsSerializable {
		INTEGER, STRING, DATE, REF
	};
	
	public enum Operator implements IsSerializable {
		EQUALS {
			@Override
			public String getSymbol() {
				return "=";
			}
		},
		
		GREATERTHAN {
			@Override
			public String getSymbol() {
				return ">";
			}
		},
		
		LESSERTHAN {
			@Override
			public String getSymbol() {
				return "<";
			}
		},
		
		GREATERTHANEQUALS {
			@Override
			public String getSymbol() {
				return ">=";
			}
		},
		
		IN {
			@Override
			public String getSymbol() {
				return "IN";
			}
		},
		
		LIKE {
			@Override
			public String getSymbol() {
				return "LIKE";
			}
		},
		
		ISNULL {
			@Override
			public String getSymbol() {
				return "IS NULL";
			}
		},
		
		ISNOTNULL {
			@Override
			public String getSymbol() {
				return "IS NOT NULL";
			}
		},
		
		BETWEEN {
			@Override
			public String getSymbol() {
				return "BETWEEN";
			}
		},
		
		
		ORDER {
			@Override
			public String getSymbol() {
				return "ORDER";
			}
		},
		
		OR {
			@Override
			public String getSymbol() {
				return "OR";
			}
		},
		
		LIKEIN {
			@Override
			public String getSymbol() {
				return "LIKEIN";
			}
		};
		
		public abstract String getSymbol();

	};
	
	private String sVal;
	private int iVal;
	private Date dVal;
	private String field;
	private Operator op;
	private Type type;
	private List<WhereBean> list = null;
	private String keyEquals;
	private String tableName;
	
	public WhereBean() {
		
	}
	
	public WhereBean(String field, String val, Operator op) {
		this.field = field;
		this.sVal = val;
		this.op = op;
		this.type = Type.STRING;
	}
	
	public WhereBean(String keyEquals, String tableName) {
		this.keyEquals = keyEquals;
		this.tableName = tableName;
		this.type = Type.REF;
	}
	
	public WhereBean(String field, int val, Operator op) {
		this.field = field;
		this.iVal = val;
		this.op = op;
		this.type = Type.INTEGER;
	}
	
	public WhereBean(String field, Date val, Operator op) {
		this.field = field;
		this.dVal = val;
		this.op = op;
		this.type = Type.DATE;
	}
	
	public String getSVal() {
		return this.sVal;
	}	
	public void setSVal(String sVal) {
		this.sVal = sVal;
	}
	
	public Date getDVal() {
		return this.dVal;
	}	
	public void setDVal(Date dVal) {
		this.dVal = dVal;
	}
	
	public String getDValString() {
		java.sql.Date sqlDate = new java.sql.Date(this.dVal.getTime());
		return sqlDate.toString();
	}
	
	public int getIVal() {
		return this.iVal;
	}	
	public void setIVal(int iVal) {
		this.iVal = iVal;
	}
	
	public String getField() {
		return this.field;
	}	
	public void setField(String field) {
		this.field = field;
	}
	
	public Operator getOp() {
		return this.op;
	}	
	public void setOp(Operator op) {
		this.op = op;
	}
	public Type getType() {
		return this.type;
	}	
	public void setType(Type type) {
		this.type = type;
	}
	
	public String getKeyEquals() {
		return this.keyEquals;
	}	
	public void setKeyEquals(String keyEquals) {
		this.keyEquals = keyEquals;
	}
	
	public String getTableName() {
		return this.tableName;
	}	
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
		
	public List<WhereBean> getList() {
		return this.list;
	}	
	public void setList(List<WhereBean> list) {
		this.list = list;
	}
}
